﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniMana.Utils.Controls;

namespace UniMana.Data
{
    public class System_GroupInfo
    {
        public bds m_bds = new bds();
        private DBMain m_data = new DBMain();

        public System_GroupInfo(int _iSystemGroupKey)
        {
            var Iquery = m_data.m_DCSave.System_Groups.Where(p => p.System_GroupKey == _iSystemGroupKey);
             m_bds.DataSource = Iquery;
             var Row = Iquery.FirstOrDefault();
             if (Row == null)
             {
                 System_Group sys_Group = new System_Group();
                 sys_Group.System_GroupKey = _iSystemGroupKey;
                 Row = sys_Group;
                 m_bds.Add(Row);
                 m_bds.MoveLast();
             }
        }
        public System_GroupInfo(string _strGroupName)
        {
            var Iquery = m_data.m_DCSave.System_Groups.Where(p => p.Name == _strGroupName);
            m_bds.DataSource = Iquery;
            var Row = Iquery.FirstOrDefault();
            if (Row == null)
            {
                System_Group sys_Group = new System_Group();
                sys_Group.Name = _strGroupName;
                Row = sys_Group;
                m_bds.Add(Row);
                m_bds.MoveLast();
            }
        }
        public System_Group Properties
        {
            get { return m_bds.Current as System_Group; }

        }

        public void Delete()
        {
            m_bds.DeleteCurrent();
        }

        public void Save()
        {
            m_bds.EndEdit();
            m_data.m_DCSave.SubmitChanges();
        }
    }
}
